package com.cn.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class NioServer3 {

  public static void main(String[] args) {
    try {
      ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();

      serverSocketChannel.bind(new InetSocketAddress(9090));
      //加上 blocking 之后 accept就不阻塞了
      serverSocketChannel.configureBlocking(false);

      while (true) {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        // 获取一个稳定的  socketchannel
        SocketChannel accept = serverSocketChannel.accept();
        System.out.println(accept);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}
